<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<%@page import="com.oracle.xiaomi.pojo.*" %>--%>
<%@page import="java.util.*" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript">
        if ("${del}" != "") {
            alert("${del}");
        }
    </script>
    <c:remove var="del"></c:remove>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bright.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/addBook.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
>

    <title></title>
</head>

<body>
<div id="brall">
    <div id="nav">
        <p>订单管理</p>
    </div>
    <div id="condition" style="text-align: center">
        <form id="myform" action="${pageContext.servletContext.contextPath}/order/mySplict.action" method="post">
            订单编号：<input name="oid" id="oid" value="${sessionScope.ordervo.oid}">&nbsp;&nbsp;&nbsp;
            用户名  ：<input name="uname" id="uname" value="${sessionScope.ordervo.uname}">&nbsp;&nbsp;&nbsp;
            <input type="submit" value="查询" />
        </form>
    </div>
    <br>
    <div id="table">
        <c:choose>
            <c:when test="${ord.list.size()!=0}">

                <!--显示分页后的订单-->

                    <div id="middle">
                        <table class="table table-bordered table-striped">
                            <tr>

                                <th>订单号</th>
                                <th>用户名</th>
                                <th>状态</th>
                                <th>总金额</th>
                                <th>时间</th>

                                <th>操作</th>
                            </tr>

                            <c:forEach items="${ord.list}" var="o">
                                <tr>
                                    <td>${o.oid}</td>
                                    <td>${o.user.uname}</td>
                                    <td style="color: ${o.status == '未支付' ? 'red' :
                                                        o.status == '待发货' ? 'orange' :
                                                        o.status == '已完成' ? 'green' :
                                                        o.status == '已取消' ? 'gray' : 'black'};">
                                            ${o.status}
                                    </td>
                                    <td>${o.totalprice}</td>
                                    <td><fmt:formatDate value="${o.odate}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
                                    <td>
                                        <c:choose>
                                            <c:when test="${o.status == '未支付'}">
                                                <button type="button" class="btn btn-primary" onclick="pay(${o.oid})">催促支付</button>
                                            </c:when>
                                            <c:when test="${o.status == '待发货'}">
                                                <button type="button" class="btn btn-warning" onclick="ship(${o.oid})">点击发货</button>
                                            </c:when>
                                            <c:when test="${o.status == '待收货'}">
                                                <!-- 已完成状态显示查看详情按钮 -->
                                                <button type="button" class="btn btn-shouhuo" onclick="shouhuo(${o.oid})">提醒收货</button>
                                            </c:when>
                                            <c:when test="${o.status == '已完成'}">
                                                <button type="button" class="btn btn-success" onclick="viewDetails(${o.oid})">查看详情</button>
                                            </c:when>
                                            <c:otherwise>
                                                <button type="button" class="btn btn-secondary" disabled>无法操作</button>
                                            </c:otherwise>
                                        </c:choose>
                                    </td>
                                </tr>
                            </c:forEach>
                        </table>

                        <!--分页栏-->
                        <div id="bottom">
                            <ul class="pagination">
                                <li>
                                    <a href="#">[总共页${ord.pages}]/[当前${ord.pageNum}]</a>
                                </li>
                                <li>
                                    <a href="${pageContext.servletContext.contextPath}/order/mySplict.action?page=1&oid=${sessionScope.ordervo.oid}&uname=${sessionScope.ordervo.uname}">首页</a>
                                </li>
                                <li>
                                    <a href="${pageContext.servletContext.contextPath}/order/mySplict.action?page=${ord.prePage}&oid=${sessionScope.ordervo.oid}&uname=${sessionScope.ordervo.uname}">上一页</a>
                                </li>
                                <li>
                                    <a href="${pageContext.servletContext.contextPath}/order/mySplict.action?page=${ord.nextPage}&oid=${sessionScope.ordervo.oid}&uname=${sessionScope.ordervo.uname}">下一页</a>
                                </li>
                                <li>
                                    <a href="${pageContext.servletContext.contextPath}/order/mySplict.action?page=${ord.pages}&oid=${sessionScope.ordervo.oid}&uname=${sessionScope.ordervo.uname}">尾页</a>
                                </li>
                            <ul/>
                        </div>
                    </div>
                </form>
            </c:when>
            <c:otherwise>
                <div>
                    <h2 style="width:1200px; text-align: center;color: orangered;margin-top: 100px">暂时没有符合条件的商品！</h2>
                </div>
            </c:otherwise>
        </c:choose>
    </div>


</div>

<!--编辑的模式对话框-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">新增商品</h4>
            </div>
            <div class="modal-body" id="addTD">
                <form action="${pageContext.request.contextPath}/admin/product?flag=save" enctype="multipart/form-data" method="post" id="myform">
                    <table>
                        <tr>
                            <td class="one">商品名称</td>
                            <td><input type="text" name="pname" class="two" class="form-control"></td>
                        </tr>
                        <!--错误提示-->
                        <tr class="three">
                            <td class="four"></td>
                            <td><span id="pnameerr"></span></td>
                        </tr>
                        <tr>
                            <td class="one">商品介绍</td>
                            <td><input type="text" name="pcontent" class="two" class="form-control"></td>
                        </tr>
                        <!--错误提示-->
                        <tr class="three">
                            <td class="four"></td>
                            <td><span id="pcontenterr"></span></td>
                        </tr>
                        <tr>
                            <td class="one">定价</td>
                            <td><input type="number" name="pprice" class="two" class="form-control"></td>
                        </tr>
                        <!--错误提示-->
                        <tr class="three">
                            <td class="four"></td>
                            <td><span id="priceerr"></span></td>
                        </tr>

                        <tr>
                            <td class="one">图片介绍</td>
                            <td><input type="file" name="pimage" class="form-control"></td>
                        </tr>
                        <tr class="three">
                            <td class="four"></td>
                            <td><span></span></td>
                        </tr>

                        <tr>
                            <td class="one">总数量</td>
                            <td><input type="number" name="pnumber" class="two" class="form-control"></td>
                        </tr>
                        <!--错误提示-->
                        <tr class="three">
                            <td class="four"></td>
                            <td><span id="numerr"></span></td>
                        </tr>


                        <tr>
                            <td class="one">类别</td>
                            <td>
                                <select name="typeid" class="form-control">
                                    <c:forEach items="${typeList}" var="type">
                                        <option value="${type.typeId}">${type.typeName}</option>
                                    </c:forEach>
                                </select>
                            </td>
                        </tr>
                        <!--错误提示-->
                        <tr class="three">
                            <td class="four"></td>
                            <td><span></span></td>
                        </tr>

                        <tr>
                            <td>
                                <input type="submit" class="btn btn-success" value="提交" class="btn btn-success">
                            </td>
                            <td>
                                <button type="button" class="btn btn-info" data-dismiss="modal">取消</button>
                            </td>
                        </tr>
                    </table>
                </form>

            </div>

        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>
</body>
<!--弹出新增模式对话框-->--%>
<script type="text/javascript">
    $(function () {
        $(".btn-info").on("click", function () {
            //浏览不关，第二次打开时要清空
            $("#myModal").modal("hide");

        });
        //新增学生非空判断
        $(".btn-success").on("click", function () {
            $("#myModal").modal("hide");
        });
    });
</script>

<script type="text/javascript">
    function mysubmit() {
        $("#myform").submit();
    }
    function del(pid,ispage) {
        if (confirm("确定删除吗")) {
            location.href = "${pageContext.request.contextPath}/prod/delete.action?pid="+pid+"&ispage="+ispage;
        }
    }

    function one(pid,ispage) {
        location.href = "${pageContext.request.contextPath}/prod/one.action?pid="+pid+"&ispage="+ispage;
    }
</script>

<!--分页的AJAX实现-->
<script type="text/javascript">
    function split(page) {

        //取出所有的条件
        var oid=$("#oid").val();
        var uname=$("#uname").val();


        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/order/ajaxSplit.action",
            data: { "page": page,"uname":uname,"oid":oid},
            success: function () {
                $("#table").load("http://localhost:8080/admin/order.jsp #table")
            },
            error: function (e) {
                alert(e.message);
            }
        });
    }
</script>

</html>